package com.shop.feignClient.fallbackFactory;

import com.shop.feignClient.GoodsClient;
import com.shop.po.R;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * @author 'banxia'
 * @version 1.0
 * @description TODO
 * @date 2023/2/25 19:47
 */
@Slf4j
@Component
public class GoodsFallback implements FallbackFactory<GoodsClient> {

    @Override
    public GoodsClient create(Throwable throwable) {
        return new GoodsClient() {
            @Override
            public R goodsCountUpdate(Long goodsId, Long count) {
                log.error("更新库存失败，被熔断了");
                log.error("异常信息：{}",throwable.getMessage());
                return R.error("调用feign更新库存被熔断");
            }

            @Override
            public R getByGoodsIdFromRedis(Long id) {
                log.error("获取商品数据异常，被熔断了。");
                log.error("异常信息:{}",throwable.getMessage());
                return R.error("获取商品数据失败");
            }
        };
    }
}
